<%@ page import="com.lengmou.service.GoodsService" %>
<%@ page import="com.lengmou.service.impl.GoodsServiceImpl" %>
<%@ page import="com.lengmou.entity.Cars" %>
<%@ page import="com.lengmou.entity.Goods" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" trimDirectiveWhitespaces="true" errorPage="error.jsp" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <meta name="apple-mobile-web-app-title" content="魔法集市">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=1200">
    <meta name="keywords" content="GSC,寿屋,万代,眼镜工厂,千值练,海洋堂,粘土人,MAXFACTORY,ALTER,良笑,三丽鸥,Sanrio,Takaratomy,KADOKAWA,Chara-ani,AmiAmi,手办自营,周边自营,谷子自营">
    <meta name="description" content="魔法集市·自营是专注于二次元的日本代购网站以及动漫周边自营零售网站，为用户提供快捷方便的游戏动漫代购，ACG周边、声优周边、同人商品及其他日系商品一应俱全，目前支持日本亚马逊、虎穴(虎之穴)、骏河屋、Book-off、C-queen(K-books)和Melonbooks(蜜瓜)等网站的代购。与此同时，魔法集市・自营整合来自日本的第一手货源，为大家精心挑选了各种热门人气商品。所有商品均从魔法集市的日本仓库打包发出，配合全新的「喵急便」物流服务直接送达您的手中，您将能获得焕然一新的消费体验">
    <link rel="icon" href="http://masadora-js.masadora.net/static/new_masadora/images/favicon/masadora-icon.png">
    <link rel="apple-touch-icon" href="http://masadora-js.masadora.net/static/new_masadora/images/favicon/masadora-icon.png">
    <link rel="apple-touch-icon-precomposed" href="http://masadora-js.masadora.net/static/new_masadora/images/favicon/masadora-icon.png">
    <title>我的购物车</title>
    <script src="js/jquery-3.1.0.js"></script>
    <script src="js/cars.js"></script>
    <script>
        $(function () {
            check();
            $('button[action="删除"]').click(function () {
                if(confirm("您确定要删除该商品吗？")){
                    var carid = $(this).parent().parent().attr("data-id");
                    var i = deleteCars(carid);
                    check();
                    i.done(function (date) {
                        if(date.deleteCarState>0){
                            $("#tishi").html("删除成功").attr("class","ui-toast-box");
                            setTimeout(function () {$("#tishi").attr("class","ui-toast-box h");location.href="cars.jsp"},1000);
                        }else{
                            $("#tishi").html("删除失败，请检查网络").attr("class","ui-toast-box");
                            setTimeout(function () {$("#tishi").attr("class","ui-toast-box h");},1000);
                        }
                    });
                }
            });
            $(".add").click(function () {
                var num=parseInt($(this).prev().prev().val())+1 ;
                $(this).prev().prev().val(num);
                var userid = $("#user").attr("date-userid");
                check();
                if(userid!=undefined){
                    var carid = $(this).attr("data-id");
                   var i = setCarsNum(carid,num);
                    i.done(function (date) {
                        if(date.setCarNumState>0){
                        }else{
                            $("#tishi").html("数据更新失败，请检查您的网络").attr("class","ui-toast-box");
                            setTimeout(function () {$("#tishi").attr("class","ui-toast-box h");location.href="cars.jsp";},1000);
                        }
                    });
                }else{
                    location.href="login.jsp";
                }
            });
            $(".reduce").click(function () {
                var num=parseInt($(this).prev().val())-1 ;
                if(num!=0){
                    $(this).prev().val(num);
                    var userid = $("#user").attr("date-userid");
                    if(userid!=undefined){
                        var carid = $(this).attr("data-id");
                        var i = setCarsNum(carid,num);
                        check();
                        i.done(function (date) {
                            if(date.setCarNumState>0){
                            }else{
                                $("#tishi").html("数据更新失败，请检查您的网络").attr("class","ui-toast-box");
                                setTimeout(function () {$("#tishi").attr("class","ui-toast-box h");location.href="cars.jsp";},1000);

                            }
                        });
                    }else{
                        location.href="login.jsp";
                    }
                }
            });

            $('input[action="单选"]').click(function () {
                check();
                checkedState();
            });
            $('input[action="全选"]').click(function () {
                var falg = $(this).prop('checked');
                var $tr= $(".carts-box").find(".cart-item-box");
                if(falg){
                    $('input[action="全选"]').prop('checked',true);
                }else{
                    $('input[action="全选"]').prop('checked',false);
                }
                $tr.each(function () {
                    if(falg){
                        $(this).find('input[action="单选"]').prop('checked',true);
                    }else{
                        $(this).find('input[action="单选"]').prop('checked',false);
                    }
                });
                check();
            });
            $('button[action="删除所选商品"]').click(function () {
                var $dan = $('input[action="单选"]');
                var num = 0;
                if(confirm("您确定要选定的商品吗？")){
                    $dan.each(function () {
                        if($(this).prop('checked')){
                            if($(this).attr("data-id").length!=0){
                               var carid= $(this).attr("data-id");
                                var i= deleteCars(carid);
                                i.done(function (date) {
                                    if(date.deleteCarState>0){

                                    }else{
                                        $("#tishi").html("删除失败，请检查网络").attr("class","ui-toast-box");
                                        setTimeout(function () {$("#tishi").attr("class","ui-toast-box h");},1000);
                                    }
                                });
                                num++
                            }
                        }
                    });
                    if(num==0){
                        $("#tishi").html("没有勾选任何商品").attr("class","ui-toast-box");
                        setTimeout(function () {$("#tishi").attr("class","ui-toast-box h");},1000);
                    }else{
                        $("#tishi").html("删除成功").attr("class","ui-toast-box");
                        setTimeout(function () {$("#tishi").attr("class","ui-toast-box h");location.href="cars.jsp";},1000);
                    }
                }
            });

            $('button[action="结算"]').click(function () {
                buy(getCarsid());
            });
        });
    </script>
</head>
<body>
<%@include file="header.jsp"%>
<div id="M">
    <div class="view view-cart">
        <title>购物车</title>
        <div class="bg-white">
            <div class="ui-layout">
                <div class="view-cart-box">
                    <div class="head">
                        <h1 class="active"> 自营购物车 <b class="cart-all-number"><!--商品数量--></b> </h1>
                    </div>
                    <div class="ctrl-box top">
                        <label class="check-all-label wm15"> <input type="checkbox" action="全选" /> 全选 </label>
                        <span class="wm4">商品信息</span>
                        <span class="wm1 tac">单价</span>
                        <span class="wm15 tac">数量</span>
                        <span class="wm1 tac">金额</span>
                        <span class="wm1 tac">操作</span>
                    </div>
                    <div style="margin: 15px 0 0;padding: 10px 45px;border-radius: 6px;background: #fff2dd;border: 1px solid #F1F1F1;color: #595467;">
                        自营日本仓商品单笔满 249 元即可包邮
                        <a href="/product/search?keyword=%E6%89%AD%E8%9B%8B" style="color:#0F87D9;margin-left:1em;">凑包邮 &gt;</a>
                    </div>
                    <div class="carts-box">
                      <c:forEach items="${cars}" var="car">
                          <div class="cart-item-box" data-id="${car.id}">
                              <%
                                  Cars car = (Cars) pageContext.getAttribute("car");
                                  GoodsService gs = new GoodsServiceImpl();
                                  Goods goods = gs.queryGoodsByGoodsId(car.getGoodsid());
                                  pageContext.setAttribute("goods",goods);
                              %>
                              <div class="good-info-box">
                                  <label class="check-item-label"><input type="checkbox" action="单选" data-id="${car.id}" /> </label>
                                  <a href="goodsinfo.jsp?goodsid=${goods.id}" target="_blank">
                                      <div class="cover-box">
                                          <img src="${goods.img}" />
                                      </div>
                                      <div class="info-box">
                                          <h4>${goods.goodsname}</h4>
                                          <div class="tags-box">
                                              <span data-name="预售">预售</span>
                                              <span data-name="跨境购">跨境购</span>
                                          </div>
                                      </div><p class="spec-item">规格：默认</p></a>
                              </div>
                              <span class="price wm1" id="price-one">${goods.price}</span>
                              <div class="num-box">
                                  <div class="ui-input-number runing">
                                      <input min="1" max="10" value="${car.num}" id="num" />
                                      <a class="reduce" data-id="${car.id}"></a>
                                      <a class="add" data-id="${car.id}"></a>
                                  </div>
                              </div>
                              <div class="calc-price-box">
                                  <b>全款：<span class="price-item" data-price="${goods.price}">248</span> 元</b>
                              </div>
                              <div class="ctrl-box">
                                  <button class="nostyle" data-id="" action="加入收藏夹">加入收藏夹</button>
                                  <button class="nostyle" data-id="" action="删除">删除</button>
                              </div>
                          </div>
                      </c:forEach>
                        <c:if test="${cars.size()==0}" >
                            <p class="text-banner" style="padding:60px 20px;">尚无内容，请去寻找喜欢的商品。</p>
                        </c:if>
                    </div>
                    <div class="ctrl-box bottom">
                        <label class="check-all-label"> <input type="checkbox" action="全选" /> 全选 </label>
                        <div class="buttons-box">
                            <button class="nostyle" action="删除所选商品">删除所选商品</button>
                            <button class="nostyle" action="收藏所选商品">收藏</button>
                        </div>
                        <div class="calc-box">
                            <span> 已选 <big class="cart-checked-number">0</big> 件商品 </span>
                            <span> 总计（不含运费）： <big class="cart-all-price-number">0</big> </span>
                            <button class="btn big" action="结算">去结算</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<%@include file="foot.jsp"%>
<div id="tishi" class="ui-toast-box h"></div>
</body>
</html>
